//
//  IdentityViewController.m
//  TheRoadAD
//
//  Created by baixue on 16/8/17.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "IdentityViewController.h"
#define cellItem @[@"个人",@"车友会",@"汽车协会",@"改装商家",@"汽车销售行",@"XXXXXXX"]
@interface IdentityViewController ()
{
    UIButton *_button;
    UIView *_autoWidthViews;
    UIView *_autoMarginViews;
}
@property (nonatomic,strong) UIButton *selectedBtn;
@end
static NSString *const ID = @"ItemCell";

@implementation IdentityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     self.title = @"身份";
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = NO;
    
    // 设置一排固定间距自动宽度子view
    [self setupAutoWidthViewsWithCount:6 margin:10];
    [self setFooterButton];
    
}

// 设置一排固定间距自动宽度子view
- (void)setupAutoWidthViewsWithCount:(NSInteger)count margin:(CGFloat)margin
{
    _autoWidthViews = [[UIView alloc] init];
    [self.view addSubview:_autoWidthViews];
    
    int i = 0;
    NSMutableArray *temp = [NSMutableArray new];
    for (i = 0; i < count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        _button = button;
        [button setTitle:cellItem[i] forState:0];
        button.tag = 1000 + i;
        [button setTitleColor:[UIColor blackColor] forState:0];
        button.titleLabel.font = [UIFont fontWithName:@"qingyuan" size:17.0f];
//        button.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1];
        button.backgroundColor = [UIColor whiteColor];
        [_autoWidthViews addSubview:button];
        button.sd_layout.autoHeightRatio(0.6); //设置高度约束
        
        [button setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [button setBackgroundImage:[UIImage imageNamed:@"tabbar-light"] forState:UIControlStateHighlighted];
        [button setBackgroundImage:[UIImage imageNamed:@"tabbar-light"] forState:UIControlStateSelected];
       
         button.contentMode = UIViewContentModeCenter;
        [button addTarget:self action:@selector(titleBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [temp addObject:button];
    }
    
    _autoWidthViews.sd_layout
    .leftSpaceToView(self.view, 10)
    .rightSpaceToView(self.view, 10)
    .topSpaceToView(self.view, 10);
    
    // 此步设置之后_autoWidthViewsContainer的高度可以根据子view自适应
    [_autoWidthViews setupAutoWidthFlowItems:[temp copy] withPerRowItemsCount:3 verticalMargin:margin horizontalMargin:margin verticalEdgeInset:4 horizontalEdgeInset:10];
    
}

-(void)titleBtnClick:(UIButton *)btn
{
    if (btn!= self.selectedBtn) {
        
        self.selectedBtn.selected = NO;
        btn.selected = YES;
        self.selectedBtn = btn;
        
    }else{
        self.selectedBtn.selected = YES;
    }

}

//
-(void)setFooterButton{
    UIButton *sureBtn = [UIButton buttonWithType:0];
    [self.view addSubview:sureBtn];
    [sureBtn setTitle:@"确定" forState:0];
    
    [sureBtn setTitleColor:[UIColor blackColor] forState:0];
    [sureBtn setBackgroundColor:[UIColor colorWithRed:0.35 green:0.87 blue:0.85 alpha:1]];
    
    sureBtn.sd_layout
    .topSpaceToView(_autoWidthViews,40)
    .leftSpaceToView(self.view,20)
    .heightIs(50 * Screen_Height/736)
    .rightSpaceToView(self.view,20);
    
    
}


@end
